<?php
namespace app\index\controller;

use app\common\model\CompanyManualOrder as CompanyManualOrderModel;

/**
 * 线下记账控制器
 * Class Companymanualorder
 * @package app\index\controller
 */
class Companymanualorder extends Base
{
    /**
     * [index  线下记账账单]
     * @return json
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $model = new CompanyManualOrderModel;
        $this->getPageAndSize($param);
        $user = $this->user;
        $map = [];
        try{
            if (!empty($param['tel'])) {
                $map['tel'] = ['like', "%" . $param['tel'] . "%"];
            }
            $map['comid'] = $user['comid'];
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getList($map, $this->from, $this->size);
        }catch (\Exception $e) {
            systembug($e->getMessage(),3,$this->url);
            return admin_json(-1, $e->getMessage());
        }
        writelog($user['mid'],$user['comid'],'查看记账');
        return admin_json(1, '获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
    /**
     * [add  添加记账]
     * @return json
     * @author [C。]
     */
    public function add()
    {
        $model = new CompanyManualOrderModel;
        $param = input('param.');
        $user = $this->user;
        try{
            $param['comid'] = $user['comid'];
            $model->addData($param);
        }catch(\Exception $e){
            systembug($e->getMessage(),3,$this->url);
            return admin_json(-1, '添加失败'.$e->getMessage());
        }
        return admin_json(1, '添加成功');
    }
}